<?php
/**
 * 系统管理模块.
 * User: 1874
 * Date: 2019/5/8
 * Time: 15:05
 */

namespace app\adminplatform\controller;

use app\adminplatform\model\System as SystemModel;
use app\adminplatform\model\Log;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Session;
use think\facade\View;

class System extends Initial {
    /*
     * 平台设置
     */
    public function website(){
        //获取系统设置
        $info = Db::name('system')->where('sy_id',1)->find();

        View::assign('info',$info);
        return View::fetch('website');
    }
    /*
     * 平台设置修改
     */
    public function websiteUpdate(){
        $map = input();
        //平台开启
        $map['sy_open'] == 'true' ? $map['sy_open'] = 1 : $map['sy_open'] = 0;
        //更新数据
        $info = SystemModel::update($map, ["sy_id"=>1]);
        if($info){
            //清除平台信息redis
            Cache::delete('website');
            //写入日志
            Log::logAdd(Session::get('userData.ad_id'),'更新平台设置');

            $data = ['info'=>'修改成功','status'=>1];
        }else{
            $data = ['info'=>'修改无变化','status'=>0];
        }
        return json($data);
    }
}